<%@page import="isquirrel.util.Utilities"%>
<%@page import="isquirrel.UserManager"%>
<%@page import="isquirrel.beans.User" %>
<%@page import="isquirrel.beans.Friend" %>
<%@page import="isquirrel.beans.Interest" %>
<%@page import="java.util.Vector" %>
<%@page import="java.text.DecimalFormat" %>
<%@page import="java.util.Set" %>
<%@page import="java.util.Iterator" %>
<%@page import="java.util.HashMap" %>
<%
HashMap<Long,String> allUsers = (HashMap<Long,String>) request.getAttribute("users");

User user = (User) request.getAttribute("user");
%>

<%// Set<User> friends = user.getFriends(); %>

<% if (allUsers.size() > 0) { 
		
	   Set<Long> uids = allUsers.keySet();
       for (Long uid : uids) {
	        User u = UserManager.getUser(uid);
%>
	<div id='<%=u.getUserID() %>' style="height: 54px;" class='friendcontainer'> 
		<%
			String pic = allUsers.get(uid);
			if (!pic.contains("http://")){
				pic = "/" + request.getRequestURI().split("/")[1] + "/images/" + pic;
			}
		%>
		<img class='friendimg' src='<%= pic %>' />
		<div style='width:85%' class='frienddetails'>
			<div style='font-weight:bold' class='friendname'><%=u.getFullName() %> <span style='color:#bbb'><%= u.getUsername() %></span>
				<% if (user.getFriends().contains(u)) { %>
					<span class='stopfollow' onclick="stopfollow(this,<%= u.getUserID() %>)">Remove from friends</span>
					<% } else { %>
					<span class='follow' onclick="follow(this,<%= u.getUserID() %>)">Add to friends</span>
					<% } %>
			</div>
			<div style='margin-bottom:2px'>
	        Interests:
	        <b>
			<% Iterator<Interest> it = u.getInterests().iterator();
			String interests = "";
			while (it.hasNext()){
				interests += it.next().getLabel() + ", ";
			}
			if (interests.equals("")){
				interests = "None (so far).";
			}
			else{
				interests = interests.substring(0, interests.length() - 2);
			}
			String tooltip = interests;
			if (interests.length() > 50) interests = interests.substring(0,48).trim() + "...";
			%>
			<span title="<%= tooltip %>"><%= interests %></span>
			</b>
	        </div>
	        <div style='margin-bottom:1px'>
	        	<%
	        	DecimalFormat df = new DecimalFormat("#0.00");
	    		String pf =  df.format(user.compare(u));
	        	%>
				Profile match: <%= pf %>										        
	        </div>
		</div>
	</div>

	<% } %> 
<% } else { %>
No people found.
<% } %>